package com.klangner.game.board.impl;

import com.klangner.game.board.IBoard;
import com.klangner.game.board.Move;

/**
 * This class implements basic board functionality.
 * No rules are exposed on 
 * @author klangner
 *
 */
public class SimpleBoard implements IBoard {

	/** Board size */
	private int			boardSize;
	/** board data */
	private int[][] goban;
	
	/**
	 * Constructor
	 */
	public SimpleBoard(int size){

		boardSize = size;
		initBoard();
	}
	
	/**
	 * Private constructor for creating object copy
	 */
	private SimpleBoard(int size, int[][] data){

		boardSize = size;
		goban = new int[boardSize][boardSize];
		for (int x = 0; x < boardSize; x++){
      for (int y = 0; y < boardSize; y++){
      	goban[x][y] = data[x][y];
      }
		}
	}
	
	/**
	 * @see IBoard#addStone(Move)
	 */
	@Override
	public void setStone(int x, int y, int color) {
		
		goban[x][y] = color;
	}
	
	/**
	 * @see IBoard#getSize()
	 */
	@Override
	public int getSize() {
		return boardSize;
	}

	/**
	 * @see IBoard#getStone(int, int)
	 */
	@Override
	public int getStone(int x, int y) {
		return goban[x][y];
	}

	/**
	 * @see IBoard#makeCopy()
	 */
	@Override
	public IBoard makeCopy() {

		return new SimpleBoard(boardSize, goban);
	}

	


	/**
	 * Init board data
	 */
	private void initBoard() {
		
		goban = new int[boardSize][boardSize];
    
		for (int x = 0; x < boardSize; x++){
      for (int y = 0; y < boardSize; y++){
      	goban[x][y] = IBoard.NO_STONE;
      }
		}
	}


}
